package part2;

import part1.Piece;

/**
 * <p>Title: Project 10 part 2</p>
 * <p>Description: CS 235 Project #10 pt. 2
 *       Shows how to set up Preconditions and Postconditions.<br/>
 *       We also look at assertions and enumeration types.</p>
 *       
 * Part1 class is a client of the Piece class
 * 
 * @author Anthony Varghese
 * @date   February 5th 2012
 * @version 1.0
 */

public class Part2 {

	/**
	 * main - main method for Part2 program<br/>
	 * 
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Piece p1 = new Piece( 10, 20 );
		for (int i=10; i>=0; i-- ) {
			double hyp = 50.0;
			double x   = 10 * i;
			System.out.println(" p1.compute( " + hyp + ", " + x + " ) is " + p1.compute( hyp , x) );
		}
		System.out.println();
		
		Piece p2 = new Piece( 50, 40 );
		System.out.println(" p2 is at " + p2.getXposition() + ", " + p2.getYposition() );
		for (int i=0; i<10; i++ ) {
			int x = 5 * i;
			int y = 10 * i;
			p2.move( x, y );
			System.out.print(" p2 is at " + p2.getXposition() + ", " + p2.getYposition() );
			
			System.out.println(" and p1.distance(p2) is " + p1.distance( p2 ));
		}
		System.out.println();
		
		AgeData a1 = new AgeData( 10, 100.0f );
		AgeData a2 = new AgeData( 20, 50.0f );
		System.out.println( " a1 is " + a1 );
		System.out.println( " a2 is " + a2 );
		
		if ( a1.compareTo( a2 ) > 0 )
			System.out.println( " a1 > a2" );
		if ( a1.compareTo( a2 ) < 0)
			System.out.println( " a1 < a2" );
		if ( a1.compareTo( a2 ) == 0)
			System.out.println( " a1 == a2" );

		if (a1.compareTo( p1 ) > 0 )
			System.out.println( " a1 > p1" );
		
		CompareAges comp = new CompareAges();
		if (comp.compare( a1, a2) > 0 )
			System.out.println( " a1 > a2" );
		if ( comp.compare( a1, a2 ) < 0)
			System.out.println( " a1 < a2" );
		if ( comp.compare( a1, a2 ) == 0)
			System.out.println( " a1 == a2" );

		if (comp.compare( a1, p1 ) > 0 )
			System.out.println( " a1 > p1" );
		
		System.out.println("Part 2 done!");
	}
}

class CompareAges implements java.util.Comparator{
	/**
	 * compare - compares the idata in arg0 to the idata in arg1
	 * 
	 * @param - arg0 should be an instance of AgeData
	 * @param - arg1 should be an instance of AgeData
	 * @return an int that satifies the rules of Comparator.compare
	 * 
	 * @require 
	 * @ensure  
	 */
	public int compare(Object arg0, Object arg1) {
		AgeData a0 = (AgeData) arg0;
		AgeData a1 = (AgeData) arg1;
		
		return a0.getIdata() - a1.getIdata();
	}
}